package com.yaya.common.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.yaya.common.config.configure.GlobalConstant;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 响应结果
 * 
 * @author m
 */
@Data
@JsonInclude(Include.NON_NULL)
public class ResponseResult {
  /**
   * 是否加密
   */
  private Boolean encrypt = GlobalConstant.CRYPTO_ENCRYPT;
  /**
   * 加密密文
   */
  private String cipher;
  /**
   * 响应编码
   */
  private Long code;
  /**
   * 响应信息
   */
  private String message;
  /**
   * 响应数据
   */
  private Map<String, Object> data = new HashMap<String, Object>();

  /**
   * 总数标记
   */
  public static final String TOTAL_TAG = "total";
  /**
   * 记录标记
   */
  public static final String RECORDS_TAG = "records";

  public ResponseResult(Long code, String message) {
    this.code = code;
    this.message = message;
  }

  public ResponseResult(Long code, String message, Boolean encrypt) {
    this.code = code;
    this.message = message;
    this.encrypt = encrypt;
  }

  public static ResponseResult success() {
    return new ResponseResult(200L, "操作成功");
  }

  public static ResponseResult success(String message) {
    return new ResponseResult(200L, message);
  }



  public static ResponseResult error() {
    return new ResponseResult(500L, "操作失败");
  }

  public static ResponseResult error(String message) {
    return new ResponseResult(500L, message);
  }

  public static ResponseResult error(Long code,String message) {
    return new ResponseResult(code, message);
  }

  public ResponseResult put(String key, Object value) {
    this.data.put(key, value);
    return this;
  }

  public ResponseResult setEncrypt(Boolean encrypt) {
    this.encrypt = encrypt;
    return this;
  }

  public ResponseResult setCipher(String cipher) {
    this.cipher = cipher;
    return this;
  }

  public ResponseResult cleanData() {
    this.data = null;
    return this;
  }

}
